[net10.0] [iOS, Windows] Fix: Switch does not use the native default on color when OnColor is unset#29694
Merged
rmarinho merged 7 commits intodotnet:net10.0from Jun 13, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses an issue with the Switch control not using the native default "on" color when OnColor is unset on iOS and Windows. The changes update the native platform implementations for iOS, Windows, and Android to correctly clear or assign the color based on the switch state, and add UI tests to validate the behavior.
- Updated iOS SwitchExtensions to correctly clear OnTintColor and track subview background when needed.
- Revised Windows implementation to remove custom resource keys when no track color is provided.
- Improved null-checks in Android and added UI tests for issue #29693.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Core/src/Platform/iOS/SwitchExtensions.cs | Updated handling of OnTintColor and track subview background for proper native default color support. |
| src/Core/src/Platform/Windows/SwitchExtensions.cs | Modified resource key handling to remove explicit color settings when track color is unset. |
| src/Core/src/Platform/Android/SwitchExtensions.cs | Adjusted null-checking for track and thumb colors. |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29693.cs | Added automated test to verify default switch colors. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue29693.cs | Provided a sample page to manually test the Switch default color behavior. |
Comments suppressed due to low confidence (1)
src/Core/src/Platform/iOS/SwitchExtensions.cs:42
- [nitpick] Consider adding a comment to clarify why uiSwitch.OnTintColor is not reset in the off branch, noting that it is intentionally left unchanged because it only affects the switch when it is on. This would aid future maintainers in understanding the design decision.
else { if (trackColor is not null) { uIView.BackgroundColor = trackColor; } else { var fallbackColor = OperatingSystem.IsIOSVersionAtLeast(13) ? UIColor.SecondarySystemFill : DefaultBackgroundColor; uIView.BackgroundColor = fallbackColor; } }
on color when OnColor is unset
Member
Member
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
rmarinho
previously approved these changes
May 27, 2025
jsuarezruiz
suggested changes
May 28, 2025
385da84 to
c8262bb
Compare
Member
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Member
|
Ok we need to check how this works with the existing style from the template. |
Member
|
Can we rebase ? |
c8262bb to
1446993
Compare
Member
Author
@rmarinho, I have rebased the branch and resolved the conflict. |
4 tasks
rmarinho
approved these changes
Jun 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root Cause of the issue
onstate. As a result, the native defaultoncolor is not applied.Description of Change
Updated the logic to properly clear the color by setting it to null and removing the corresponding color keys on iOS and Windows.
This ensures that when OnColor is not explicitly set, the native default
oncolor is applied to the Switch as expected.Issues Fixed
Fixes #29693
Tested the behaviour in the following platforms
Screenshot
Before-Fix.mov
After-Fix.mov
Before-Fix.mov
After-Fix.mov
Before-Fix-WinUI.mp4
After-Fix-WinUI.mp4